import 'package:citiesocial/_include.dart';

///点击类型
enum ClickType { PAY, CANCEL, CINFIRM_RECEIPT, ITEM }

///点击回调
typedef OnOrderItemClick(OrderEntity order, ClickType type);

class OrderItem extends BaseStatelessWidget {
  final OrderEntity order;
  final OnOrderItemClick onOrderItemClick;
  OrderItem(this.order, [this.onOrderItemClick]);
  @override
  Widget build(BuildContext context) => GestureDetector(
        onTap: () {
          if (onOrderItemClick != null) {
            onOrderItemClick(order, ClickType.ITEM);
          }
        },
        child: Container(
          margin: EdgeInsets.only(top: 10.0),
          child: Column(
            children: <Widget>[
              Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Expanded(
                    child: Text(
                      '订单状态:  ${order.order_state == '1' ? '待付款' : order.order_state == '2' ? '待收货' : order.order_state == '3' ? '已完成' : order.order_state == '4' ? '已取消' : '未知'}',
                      style: TextStyle(fontSize: 14.0, color: Colors.red),
                    ),
                  ),
                  Offstage(
                    offstage: order?.order_state != '1',
                    child: GestureDetector(
                      child: Container(
                        child: Text(
                          '付款',
                          style: TextStyle(color: Colors.red),
                        ),
                        padding: EdgeInsets.symmetric(horizontal: 10.0),
                      ),
                      onTap: () {
                        if (onOrderItemClick != null) {
                          onOrderItemClick(order, ClickType.PAY);
                        }
                      },
                    ),
                  ),
                  Offstage(
                    offstage: order?.order_state != '1',
                    child: GestureDetector(
                      child: Container(
                        child: Text(
                          '取消',
                          style: TextStyle(color: Colors.red),
                        ),
                        padding: EdgeInsets.symmetric(horizontal: 10.0),
                      ),
                      onTap: () {
                        if (onOrderItemClick != null) {
                          onOrderItemClick(order, ClickType.CANCEL);
                        }
                      },
                    ),
                  ),
                  Offstage(
                    offstage: order?.order_state != '3',
                    child: GestureDetector(
                      child: Container(
                        child: Text(
                          '确认收货',
                          style: TextStyle(color: Colors.red),
                        ),
                        padding: EdgeInsets.symmetric(horizontal: 10.0),
                      ),
                      onTap: () {
                        if (onOrderItemClick != null) {
                          onOrderItemClick(order, ClickType.CINFIRM_RECEIPT);
                        }
                      },
                    ),
                  ),
                ],
              ),
              Container(
                margin: EdgeInsets.only(top: 5.0),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Expanded(
                      child: Text(
                        '订单号: ${order.order_sn}',
                        style: TextStyle(fontSize: 14.0, color: Colors.black),
                      ),
                    ),
                    Offstage(
                      offstage: order?.order_state != '4',
                      child: IconButton(
                        icon: Icon(
                          Icons.delete,
                          color: Colors.grey,
                        ),
                        onPressed: () {},
                      ),
                    )
                  ],
                ),
              ),
              SingleChildScrollView(
                child: Row(
                  children: List.generate(
                      (order?.goods_img?.length ?? 0),
                      (index) => Container(
                            child: Image(
                              width: 90.0,
                              height: 90.0,
                              fit: BoxFit.cover,
                              image: CachedNetworkImageProvider(
                                  '${order.goods_img[index]}'),
                            ),
                            margin: EdgeInsets.only(right: 10.0),
                          )),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Text(
                    '共${order.goods_num}件商品   实付款:',
                    style: TextStyle(fontSize: 14.0, color: Colors.black),
                  ),
                  Text(
                    '${order.total}',
                    style: TextStyle(
                        fontSize: 17.0,
                        color: Colors.black,
                        fontWeight: FontWeight.bold),
                  ),
                ],
              ),
            ],
          ),
          color: Colors.white,
          padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
        ),
      );
}
